package com.yanqu.road.server.manger.kowloon.battle.role.bullet;

import java.util.List;

import com.yanqu.road.server.manger.kowloon.battle.KowloonGame;
import com.yanqu.road.server.manger.kowloon.battle.role.enemy.KowloonEnemy;

/**
 * 落雷
 */
public class KowloonBulletFootball extends KowloonBullet {

    private int atkNum;
    /** 击退距离 */
    public double beatBackDistance;

    public KowloonBulletFootball(KowloonGame game) {
        super(game);
    }

    @Override
    public void init() {
        this.atkNum = this.shooter.data.getProperty().getAttackNum();
    }

    @Override
    public void updateAI(double dt) {
        if (this.atkNum > 0) {
            KowloonEnemy enemy = this.getHitEnemy();
            if (enemy != null) {
                this.enemyIds.add(enemy.id);
                double distance = game.distance(this.shooter.pos, this.pos);
                List<Integer> param2 = this.buffParam.getParam2();
                int p2 = param2.get(param2.size() - 1);
                for (int idx = 0; idx < param2.size(); idx++) {
//                    int dis = 100 * (+idx + 1);
//                    if (distance <= dis) {
//                        p2 = param2.get(idx);
//                        break;
//                    }
                    if (this.enemyIds.size() <= +idx + 1) {
                        p2 = param2.get(idx);
                        break;
                    }
                }
                enemy.beHurt(this.bulletType, Math.floor(+this.shooter.data.getProperty().getAttack() * p2 / 1000.0));
                if (this.speed.getY() > 0) {
                    List<Integer> param = this.buffParam.getParam();
                    this.beatBackDistance = param.get(param.size() - 1);
                    for (int idx = 0; idx < param.size(); idx++) {
                        int dis = 100 * (+idx + 1);
                        if (distance <= dis) {
                            this.beatBackDistance = param.get(idx);
                            break;
                        }
                    }
                    enemy.addBuffByBullet(this);
                }
                this.atkNum--;
                if (this.atkNum <= 0) {
                    this.destroy();
                }
            }
        }
    }
}
